<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>QJson: QObjectHelper Class Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">QJson
   &#160;<span id="projectnumber">1.0.0</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div>
<div class="header">
  <div class="summary">
<a href="#nested-classes">Classes</a> &#124;
<a href="#pub-static-methods">Static Public Member Functions</a>  </div>
  <div class="headertitle">
<div class="title">QObjectHelper Class Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Class used to convert QObject into QVariant and vivce-versa. During these operations only the class attributes defined as properties will be considered.  
 <a href="class_q_object_helper.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="qobjecthelper_8h_source.html">qobjecthelper.h</a>&gt;</code></p>

<p><a href="class_q_object_helper-members.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="nested-classes"></a>
Classes</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">class &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_q_object_helper_1_1_q_object_helper_private.html">QObjectHelperPrivate</a></td></tr>
<tr><td colspan="2"><h2><a name="pub-static-methods"></a>
Static Public Member Functions</h2></td></tr>
<tr class="memitem:ac5fd74ad328752d47e62e1ac4a50df58"><td class="memItemLeft" align="right" valign="top">static QVariantMap&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_q_object_helper.html#ac5fd74ad328752d47e62e1ac4a50df58">qobject2qvariant</a> (const QObject *object, const QStringList &amp;ignoredProperties=QStringList(QString(QLatin1String(&quot;objectName&quot;))))</td></tr>
<tr class="memitem:a69dd8a0be3fbc682f0f418882ec1337b"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_q_object_helper.html#a69dd8a0be3fbc682f0f418882ec1337b">qvariant2qobject</a> (const QVariantMap &amp;variant, QObject *object)</td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>Class used to convert QObject into QVariant and vivce-versa. During these operations only the class attributes defined as properties will be considered. </p>
<p>Suppose the declaration of the Person class looks like this: </p>
<div class="fragment"><pre class="fragment"> <span class="keyword">class </span>Person : <span class="keyword">public</span> QObject
    {
      Q_OBJECT

      Q_PROPERTY(QString name READ name WRITE setName)
      Q_PROPERTY(<span class="keywordtype">int</span> phoneNumber READ phoneNumber WRITE setPhoneNumber)
      Q_PROPERTY(Gender gender READ gender WRITE setGender)
      Q_PROPERTY(QDate dob READ dob WRITE setDob)
      Q_ENUMS(Gender)

     public:
        Person(QObject* parent = 0);
        ~Person();

        QString name() const;
        <span class="keywordtype">void</span> setName(const QString&amp; name);

        <span class="keywordtype">int</span> phoneNumber() const;
        <span class="keywordtype">void</span> setPhoneNumber(const <span class="keywordtype">int</span>  phoneNumber);

        enum Gender {Male, Female};
        <span class="keywordtype">void</span> setGender(Gender gender);
        Gender gender() <span class="keyword">const</span>;

        QDate dob() <span class="keyword">const</span>;
        <span class="keywordtype">void</span> setDob(<span class="keyword">const</span> QDate&amp; dob);

      <span class="keyword">private</span>:
        QString m_name;
        <span class="keywordtype">int</span> m_phoneNumber;
        Gender m_gender;
        QDate m_dob;
    };
</pre></div><p>The following code will serialize an instance of Person to JSON :</p>
<div class="fragment"><pre class="fragment">    Person person;
    person.setName(<span class="stringliteral">&quot;Flavio&quot;</span>);
    person.setPhoneNumber(123456);
    person.setGender(Person::Male);
    person.setDob(QDate(1982, 7, 12));

    QVariantMap variant = <a class="code" href="class_q_object_helper.html#ac5fd74ad328752d47e62e1ac4a50df58">QObjectHelper::qobject2qvariant</a>(&amp;person);
    <a class="code" href="class_serializer.html" title="Main class used to convert QVariant objects to JSON data.">Serializer</a> serializer;
    qDebug() &lt;&lt; serializer.<a class="code" href="class_serializer.html#a4789008e6d925f45af17ea1340c1e27d">serialize</a>( variant);
</pre></div><p>The generated output will be: </p>
<div class="fragment"><pre class="fragment">    { <span class="stringliteral">&quot;dob&quot;</span> : <span class="stringliteral">&quot;1982-07-12&quot;</span>, <span class="stringliteral">&quot;gender&quot;</span> : 0, <span class="stringliteral">&quot;name&quot;</span> : <span class="stringliteral">&quot;Flavio&quot;</span>, <span class="stringliteral">&quot;phoneNumber&quot;</span> : 123456 }
</pre></div><p>It's also possible to initialize a QObject using the values stored inside of a QVariantMap.</p>
<p>Suppose you have the following JSON data stored into a QString: </p>
<div class="fragment"><pre class="fragment">    { <span class="stringliteral">&quot;dob&quot;</span> : <span class="stringliteral">&quot;1982-07-12&quot;</span>, <span class="stringliteral">&quot;gender&quot;</span> : 0, <span class="stringliteral">&quot;name&quot;</span> : <span class="stringliteral">&quot;Flavio&quot;</span>, <span class="stringliteral">&quot;phoneNumber&quot;</span> : 123456 }
</pre></div><p>The following code will initialize an already allocated instance of Person using the JSON values: </p>
<div class="fragment"><pre class="fragment">    Parser parser;
    QVariant variant = parser.parse(json);

    Person person;
    <a class="code" href="class_q_object_helper.html#a69dd8a0be3fbc682f0f418882ec1337b">QObjectHelper::qvariant2qobject</a>(variant.toMap(), &amp;person);
</pre></div><dl class="section see"><dt>See also:</dt><dd>Parser </dd>
<dd>
<a class="el" href="class_serializer.html" title="Main class used to convert QVariant objects to JSON data.">Serializer</a> </dd></dl>
</div><hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="ac5fd74ad328752d47e62e1ac4a50df58"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">QVariantMap <a class="el" href="class_q_object_helper.html#ac5fd74ad328752d47e62e1ac4a50df58">QObjectHelper::qobject2qvariant</a> </td>
          <td>(</td>
          <td class="paramtype">const QObject *&#160;</td>
          <td class="paramname"><em>object</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const QStringList &amp;&#160;</td>
          <td class="paramname"><em>ignoredProperties</em> = <code>QStringList(QString(QLatin1String(&quot;objectName&quot;)))</code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td><code> [static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>This method converts a QObject instance into a QVariantMap.</p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">object</td><td>The QObject instance to be converted. </td></tr>
    <tr><td class="paramname">ignoredProperties</td><td>Properties that won't be converted. </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a class="anchor" id="a69dd8a0be3fbc682f0f418882ec1337b"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="class_q_object_helper.html#a69dd8a0be3fbc682f0f418882ec1337b">QObjectHelper::qvariant2qobject</a> </td>
          <td>(</td>
          <td class="paramtype">const QVariantMap &amp;&#160;</td>
          <td class="paramname"><em>variant</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">QObject *&#160;</td>
          <td class="paramname"><em>object</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td><code> [static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>This method converts a QVariantMap instance into a QObject</p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">object</td><td>The QObject instance to be converted. </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li><a class="el" href="qobjecthelper_8h_source.html">qobjecthelper.h</a></li>
<li>qobjecthelper.cpp</li>
</ul>
</div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Mon Apr 9 2012 23:57:46 for QJson by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.0
</small></address>

</body>
</html>
